import 'package:base_demo/components/connectivity/ConnectivityPage.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/get.dart';

void main() {
  //runApp(const MyText());
  // runApp(const MaterialAppScaffold());
  // runApp(const Image1());
  //runApp(const Image2());
  // runApp(const Image3());
  //runApp(const Image4());
  // runApp(const Image5());
  // runApp(const IconView());
  //0+----- runApp(const ListView1());
  //runApp(const ListView2());
  //runApp(const ListView3());
  //runApp(const DynamicListView1());
  //runApp(const DynamicListView2());
  // runApp(const DynamicListView3());
  //runApp(const GridViewPage());
  // runApp(const GridViewPage1());
  //runApp(const GridViewPage3());
  //runApp(const GridViewPage4());
  //runApp(const GridViewPage5());
  //runApp(const RowPage1());
  //runApp(const RowPage2());
  //runApp(const FlexExpanded1());
  //runApp(const FlexExpanded2());
  // runApp(const StackPositionedView());
  //runApp(const CardViewPage1());
  //runApp(const CardViewPage2());
  // runApp(const CardViewPage3());
  //runApp(const ButtonViewPage());
  // runApp(const WrapViewPage1());
  //runApp(const WrapViewPage2());
  //runApp(const StateLessFulWidget());
//  runApp(const ScaffoldPage1());
  //runApp(NamedRoute());  // 命名路由
  // runApp(MyApp());
  runApp(GetXMyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false, //去掉debug图标
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      localizationsDelegates: [
        //此处
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: [
        //此处
        const Locale('zh', 'CH'),
        const Locale('en', 'US'),
      ],
      // home: GoodsListPage(),
      // home: MyHomePage(),
      // home: FloatingActionButtonView(),
      //  home: AppBarViewPage(),
      // home: AppBarPageView2(),
      // home: FloatingButtonViewTabBar(),
      //  home: HomePage(),
      // home: AlertDialogView(),
      // home: SimpleDialogView(),
      // home: ShowModalBottomSheet(),
      //  home: showCusDialog(),
      //home: PageViewPage1(),
      // home: PageViewPage2(),
      //home: PageViewPage3(),
      // home: PageViewLoop(),
      //  home: PageControllerAnimateToPage(),
      // home: CustomKeepAliveWrapper(),
      // home: BoxKeyViewTest(),
      //home: LocalKeyBoxView(),
      // home: GlobalKeyGetAttribute(),
      //home: AnimatedListPage(),
      //home: TextFieldPage(),
      //home: TextFieldViewPage(),
      // home: TextinputView1(),
      // home: TextFieldLogin(),
      //home: RadioViewPage(),
      //home: CustomRadio(),
      // home: MSListTileRoute(),
      //home: IndicatorView(),
      //home: FutureDemoView(),
      // home: FutureBuilderPage(),
      // home: StramDemo(),
      //home: StreamBuilderCounter(),
      //home: StramTimer(),
      //home: StreamControllerDemo(),
      //home: StreamControllerBroadCastDemo(),
      //home: StreamBuilderFilter(),
      // home: DateViewExample(),
      // home: JsonMapView(),
      //home: DioView(),
      // home: DioRendingView(),
      // home: DioFutureRendingView(),
      // home: NewsHtmlBeforePage(),
      //  home: NewsContentPage(),
      //home: HtmlPageExample(),
      //home: DeviceInfoPage(),
      home: ConnectivityPage(),
    );
  }
}

class GetXMyApp extends StatelessWidget {
  const GetXMyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false, //去掉debug图标
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      localizationsDelegates: [
        //此处
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: [
        //此处
        const Locale('zh', 'CH'),
        const Locale('en', 'US'),
      ],

      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});
  void _alertDialog(context) async {
    var result = await showDialog(
        barrierDismissible: false, //表示点击灰色背景的时候是否消失弹出框
        context: context,
        builder: (context) {
          return AlertDialog(
            title: const Text("提示信息!"),
            content: const Text("您确定要删除吗"),
            actions: [
              TextButton(
                  onPressed: () {
                    print("ok");
                    Navigator.of(context).pop("ok"); //点击按钮让AlertDialog消失
                  },
                  child: const Text("确定")),
              TextButton(
                  onPressed: () {
                    print("cancel");
                    Navigator.of(context).pop("取消");
                  },
                  child: const Text("取消"))
            ],
          );
        });
    print("-----------");
    print(result);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Title'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
                onPressed: () {
                  _alertDialog(context);
                },
                child: const Text("Flutter默认的dialog")),
            ElevatedButton(
                onPressed: () {
                  Get.defaultDialog(
                      title: "提示信息!",
                      middleText: "您确定要删除吗?",
                      confirm: ElevatedButton(
                          onPressed: () {
                            print("确定");
                            // Navigator.of(context).pop();
                            Get.back();
                          },
                          child: const Text("确定")),
                      cancel: ElevatedButton(
                          onPressed: () {
                            print("取消");
                            Get.back();
                          },
                          child: const Text("取消")));
                },
                child: const Text("Getx defaultDialog")),
            ElevatedButton(
                onPressed: () {
                  Get.snackbar("提示?", "您还有没有登录",
                      snackPosition: SnackPosition.BOTTOM);
                },
                child: const Text("Getx snackbar")),
            ElevatedButton(
                onPressed: () {
                  Get.bottomSheet(Container(
                    color: Get.isDarkMode ? Colors.black26 : Colors.white,
                    height: 200,
                    child: Column(
                      children: [
                        ListTile(
                          leading: Icon(Icons.wb_sunny_outlined,
                              color: Get.isDarkMode
                                  ? Colors.white
                                  : Colors.black87),
                          onTap: () {
                            //切换主题
                            Get.changeTheme(ThemeData.light());
                            Get.back();
                          },
                          title: Text(
                            "白天模式",
                            style: TextStyle(
                                color: Get.isDarkMode
                                    ? Colors.white
                                    : Colors.black87),
                          ),
                        ),
                        ListTile(
                          leading: Icon(Icons.wb_sunny,
                              color: Get.isDarkMode
                                  ? Colors.white
                                  : Colors.black87),
                          onTap: () {
                            //切换主题
                            Get.changeTheme(ThemeData.dark());
                            Get.back();
                          },
                          title: Text(
                            "夜晚模式",
                            style: TextStyle(
                                color: Get.isDarkMode
                                    ? Colors.white
                                    : Colors.black87),
                          ),
                        )
                      ],
                    ),
                  ));
                },
                child: const Text("Getx bottomSheet切换主题"))
          ],
        ),
      ),
    );
  }
}
